package com.ruoyi.management.complaint.controller;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.management.complaint.ro.GetComplaintDetailParam;
import com.ruoyi.management.complaint.ro.GetComplaintHandlingParam;
import com.ruoyi.management.complaint.ro.GetComplaintListParam;
import com.ruoyi.management.complaint.service.ITOrderEvaluateService;
import com.ruoyi.management.complaint.vo.GetComplaintListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * 乘客评价Controller
 *
 * @author ZhangGuangyu
 * @date 2021-11-29
 */
@Api("乘客评价")
@Validated
@RestController
public class TOrderEvaluateController extends BaseController {

    @Autowired
    private ITOrderEvaluateService tOrderEvaluateService;

    /**
     * 投诉列表查询
     *
     * @param param
     * @return
     */
    @ApiOperation("投诉列表查询")
    @GetMapping("/tscx")
    public TableDataInfo list(@Valid GetComplaintListParam param) {
        startPage();
        List<GetComplaintListVO> list = tOrderEvaluateService.selectTOrderEvaluateList(param);
        // 查询结果判空
        if (CollectionUtils.isEmpty(list)) {
            TableDataInfo rspData = new TableDataInfo();
            rspData.setCode(HttpStatus.SUCCESS);
            rspData.setMsg("查询成功");
            rspData.setRows(list);
            rspData.setTotal(0);
            return rspData;
        }else {
            for (GetComplaintListVO vo :list)
            {
                Date evaluateTime = vo.getEvaluateTime();

                Date date = new Date();
                if (null != vo.getFinishTime())
                {
                    date = vo.getFinishTime();
                }
                String datePoor = DateUtils.getDatePoor(date,evaluateTime);

                boolean isOverdue = DateUtils.getDatePoorForComplaint(date,evaluateTime);
                if (isOverdue)
                {
                    datePoor+="(逾期)";
                }else {
                    datePoor+="(正常)";
                }
                vo.setDatePoor(datePoor);
                vo.setOverdue(isOverdue);
            }
        }
        return getDataTable(list);
    }

    /**
     * 投诉详情
     *
     * @param param
     * @return
     */
    @ApiOperation("投诉详情")
    @GetMapping("/tsxq")
    public AjaxResult selectTOrderEvaluateById(@Valid GetComplaintDetailParam param) {
        return tOrderEvaluateService.selectTOrderEvaluateById(param);
    }

    /**
     * 投诉处理
     *
     * @param param
     * @return
     */
    @GetMapping("/tscl")
    @ApiOperation("投诉处理")
    public AjaxResult complaintHandling(@Valid GetComplaintHandlingParam param) {
        return tOrderEvaluateService.complaintHandling(param);
    }
}
